package com.lvyou.service;

import com.lvyou.entity.UserModel;
import com.lvyou.mapper.IUserMapper;
import com.lvyou.model.Result;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.UUID;

@Service
public class RegSrvImpl {
    @Resource
    private IUserMapper dao;
    public Result reg(String password, String phone){
        System.out.println("RegSrvImpl"+password+phone);
        Date date=new Date();
        UserModel um=new UserModel();
        String uuid= UUID.randomUUID().toString().replace("-","");
        um.setId(uuid);
        um.setPhone(phone);
        um.setPassword(password);
        um.setName("");
        um.setRole("100");
        um.setStatus("1");
        um.setCreateTime(date);
        um.setUpdateTime(date);

        List<UserModel> list=dao.queryByPhone(phone);
        Result res=new Result();
        if(list.size()==0){
            dao.insert(um);
            //0表示可以注册
            res.setCode(0);
//            res.setMsg("可以注册");
        }else{
            //101表示重复了注册失败
            res.setCode(101);
            res.setMsg("注册失败");
        }
        return res;

    }
}